package com.dlyk.service.impl;

import com.dlyk.constant.Constants;
import com.dlyk.mapper.RoleMapper;
import com.dlyk.model.Role;
import com.dlyk.service.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleMapper roleMapper;

    /**
     * 查询所有角色（分页查询）
     */
    @Override
    public PageInfo<Role> getRoleListByPage(Integer current) {

        // 1、设置PageHelper
        PageHelper.startPage(current, Constants.PAGE_SIZE);

        // 2、查询
        List<Role> roleList = roleMapper.selectRoleListByPage(current);

        // 3、封装分页数据到PageInfo
        PageInfo<Role> rolePageInfo = new PageInfo<>(roleList);

        return rolePageInfo;
    }

    /**
     * 录入角色
     */
    @Override
    public int addRole(Role role) {
        return roleMapper.insertSelective(role);
    }

    /**
     * 编辑角色
     */
    @Override
    public int editRole(Role role) {
        return roleMapper.updateByPrimaryKeySelective(role);
    }

    /**
     * 删除角色
     */
    @Override
    public int removeRole(Integer id) {
        return roleMapper.deleteByPrimaryKey(id);
    }

}

